package com.fc.mall.portal.controller;

import com.fc.mall.base.object.Result;
import com.fc.mall.portal.domain.BargainParam;
import com.fc.mall.portal.domain.BargainQueryParam;
import com.fc.mall.portal.domain.ConfirmOrderResult;
import com.fc.mall.portal.domain.ImmediatelyBargainOrderParam;
import com.fc.mall.portal.dto.OmsBargainCartItem;
import com.fc.mall.portal.service.OmsBargainService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Sunny
 * Created by sunny on 2019/9/10.
 */

@RestController
@RequestMapping("/oms/bargain")
public class OmsBargainController {

    @Autowired
    private OmsBargainService bargainService;

    @ApiOperation("发起砍价")
    @PostMapping
    public Result handleCreateBargain(@RequestBody BargainParam bargainParam)
    {
        return  Result.success(bargainService.createBargain(bargainParam));
    }

    @ApiOperation("获取砍价详情")
    @GetMapping("{bargainId}")
    public Result handleGetBargain(@PathVariable Long bargainId)
    {
        return  Result.success(bargainService.getBargainById(bargainId));
    }

    @ApiOperation("好友帮忙砍价")
    @PutMapping("{bargainId}")
    public Result handleBargainPrice(@PathVariable Long bargainId)
    {
        return Result.success(bargainService.friendBargain(bargainId));
    }


    @ApiOperation("获取个人发起的砍价")
    @GetMapping("list")
    public Result handleGetMineBargain(BargainQueryParam bargainParam)
    {
        return  Result.success(bargainService.getBargainListOfSelf(bargainParam));
    }


    @ApiOperation("砍价创建订单")
    @PostMapping("order")
    public Result createConfirmBargainOrder(@RequestBody OmsBargainCartItem bargainCartItem)
    {
        ConfirmOrderResult orderResult = bargainService.generateConfirmBargainOrder(bargainCartItem);
        return Result.success(orderResult);
    }


    @ApiOperation("创建正式订单")
    @PostMapping("/immediately")
    public Result createGroupOrder(@RequestBody ImmediatelyBargainOrderParam immediatelyOrderParam)
    {
        return bargainService.generateBargainOrder(immediatelyOrderParam);
    }



}
